class Solution {
    public int edgeScore(int[] edges) {
        int n = edges.length;
        long[] score = new long[n];
        long ret = 1;
        long max = -1;
        for (int i = 0; i < n; i++) {
            score[edges[i]] = score[edges[i]] + i;
            if (score[edges[i]] > max) {
                max = score[edges[i]];
            }
        }
        for (int i = 0; i < n; i++) {
            if (score[i] >= max) {
                ret = i;
                break;
            }
        }
        return (int) ret;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.edgeScore(new int[]{1, 0, 0, 0, 0, 7, 7, 5}));
    }
}